package org.example.silde;

import java.util.LinkedList;

public class RecentCounter {
    private LinkedList<Integer> list;
    public RecentCounter() {
        list = new LinkedList<>();
    }
    public int ping(int t){
        list.addFirst(t);
        for(int i=0;i<list.size();i++){
            Integer last = list.getLast();
            if(last<t-30000){
                list.removeLast();
                i--;
            }else{
                break;
            }
        }
        return list.size();
    }

    public static void main(String[] args) {
//        RecentCounter recentCounter = new RecentCounter();
//
//        System.out.println(recentCounter.ping(156166));
//        System.out.println(recentCounter.ping(156423));
//        System.out.println(recentCounter.ping(158304));//3
//        System.out.println(recentCounter.ping(211387));//2
//        System.out.println(recentCounter.ping(277101));//2
        LinkedList<String> list=new LinkedList<>();
        list.add("zhangsan");
        list.add("zhangsan");
        list.add("lisi");
        for(int i=0;i<list.size();i++){
            String str = list.get(i);
            if("zhangsan".equals(str)){
                list.remove(str);
                i--;
            }
        }
        System.out.println(list);
    }
}
